package com.project.common.data.mybatis.provider;

import com.project.common.data.mybatis.annotation.Persistent;
import com.project.common.exception.BusinessException;
import org.apache.ibatis.builder.annotation.ProviderContext;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

public interface StatementProvider extends ProviderMethodResolver {

    default Class<?> getPersistenceType(ProviderContext providerContext) {
        Class<?> mapperType = providerContext.getMapperType();
        Persistent persistent = mapperType.getAnnotation(Persistent.class);
        if (persistent == null) {
            throw new BusinessException(providerContext.getMapperType().getName()
                + "未找到@Persistent注解,如果需要使用SQL语句自动生成,请添加该注解!");
        }
        return persistent.type();
    }

}
